home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / fileutil / fileutils-3.16.tar.gz / fileutils-3.16.tar / fileutils-3.16 / lib / xstrtol.h < prev    next >
C/C++ Source or Header  |  1997-01-25  |  2KB  |  70 lines

  1. #ifndef XSTRTOL_H_
  2. # define XSTRTOL_H_ 1
  3.  
  4. # if STRING_TO_UNSIGNED
  5. #  define __xstrtol xstrtoul
  6. #  define __strtol strtoul
  7. #  define __unsigned unsigned
  8. #  define __ZLONG_MAX ULONG_MAX
  9. # else
  10. #  define __xstrtol xstrtol
  11. #  define __strtol strtol
  12. #  define __unsigned /* empty */
  13. #  define __ZLONG_MAX LONG_MAX
  14. # endif
  15.  
  16. # undef PARAMS
  17. # if defined (__STDC__) && __STDC__
  18. #  define PARAMS(Args) Args
  19. # else
  20. #  define PARAMS(Args) ()
  21. # endif
  22.  
  23. #ifndef _STRTOL_ERROR
  24. enum strtol_error
  25.   {
  26.     LONGINT_OK, LONGINT_INVALID, LONGINT_INVALID_SUFFIX_CHAR, LONGINT_OVERFLOW
  27.   };
  28. typedef enum strtol_error strtol_error;
  29. #endif
  30.  
  31. strtol_error
  32.   __xstrtol PARAMS ((const char *s, char **ptr, int base,
  33.              __unsigned long int *val, const char *valid_suffixes));
  34.  
  35. #undef _STRTOL_ERROR
  36. # define _STRTOL_ERROR(Exit_code, Str, Argument_type_string, Err)    \
  37.   do                                    \
  38.     {                                    \
  39.       switch ((Err))                            \
  40.     {                                \
  41.     case LONGINT_OK:                        \
  42.       abort ();                            \
  43.                                     \
  44.     case LONGINT_INVALID:                        \
  45.       error ((Exit_code), 0, "invalid %s `%s'",            \
  46.          (Argument_type_string), (Str));            \
  47.       break;                            \
  48.                                     \
  49.     case LONGINT_INVALID_SUFFIX_CHAR:                \
  50.       error ((Exit_code), 0, "invalid character following %s `%s'",    \
  51.          (Argument_type_string), (Str));            \
  52.       break;                            \
  53.                                     \
  54.     case LONGINT_OVERFLOW:                        \
  55.       /* FIXME: make this message dependent on STRING_TO_UNSIGNED */\
  56.       error ((Exit_code), 0, "%s `%s' larger than maximum long int",\
  57.          (Argument_type_string), (Str));            \
  58.       break;                            \
  59.     }                                \
  60.     }                                    \
  61.   while (0)
  62.  
  63. # define STRTOL_FATAL_ERROR(Str, Argument_type_string, Err)        \
  64.   _STRTOL_ERROR (2, Str, Argument_type_string, Err)
  65.  
  66. # define STRTOL_FAIL_WARN(Str, Argument_type_string, Err)        \
  67.   _STRTOL_ERROR (0, Str, Argument_type_string, Err)
  68.  
  69. #endif /* not XSTRTOL_H_ */
  70.